//
//  DeatilsViewController.m
//  SuperRadio
//
//  Created by supercchome on 14/12/26.
//  Copyright (c) 2014年 三个臭皮匠. All rights reserved.
//

#import "DeatilsViewController.h"
#import "UIImageView+WebCache.h"
#import "Introduction.h"
#import "NetHandler.h"


@interface DeatilsViewController ()

@property(nonatomic, retain)UIScrollView *scrollView;
@property(nonatomic, retain)UIImageView *imageView;
@property(nonatomic, retain)UILabel *lableone;
@property(nonatomic, retain)UILabel *lableOneName;
@property(nonatomic, retain)UILabel *renzhengLable;
@property(nonatomic, retain)UILabel *renzhengNameLable;
@property(nonatomic, retain)UILabel *jianjieLable;
@property(nonatomic, retain)UILabel *jianjieNameLable;
@property(nonatomic, retain)UILabel *dingweiLable;
@property(nonatomic, retain)UILabel *dingweiNameLable;


@end

@implementation DeatilsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self getInfor];
    
//    NSLog(@"%@", [self.introduction.uid stringValue]);
    CGFloat width = self.view.frame.size.width/6;
//    CGFloat height = self.view.frame.size.height;
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.scrollView.backgroundColor = [UIColor whiteColor];
    self.scrollView = [[UIScrollView alloc]initWithFrame:self.view.bounds];
    [self.view addSubview:self.scrollView];
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    
    button.frame = CGRectMake(self.view.bounds.size.width - 50, 30, 30, 30);
    //[button setTitle:@"返回" forState:UIControlStateNormal];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"close" ofType:@"png"];
    [button setBackgroundImage:[UIImage imageWithContentsOfFile:path] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(returnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self.scrollView addSubview:button];
    
    self.imageView = [[UIImageView alloc]init];
    
    self.imageView.frame = CGRectMake(20, 64, width * 6 - 40, width*6 - 40);
   
    [self.scrollView addSubview:self.imageView];
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;
    
    self.lableone = [[UILabel alloc]initWithFrame:CGRectMake(20, _imageView.frame.origin.y + _imageView.frame.size.height + 10, width, 20)];
    self.lableone.text = @"昵称:";
    
    [self.scrollView addSubview:self.lableone];
    
    self.lableOneName = [[UILabel alloc]initWithFrame:CGRectMake(20 + 40, _imageView.frame.origin.y + _imageView.frame.size.height + 10, width * 5, 20)];
    self.lableOneName.text = self.introduction.nickname;
    [self.scrollView addSubview:self.lableOneName];
    
    
    self.renzhengLable = [[UILabel alloc]initWithFrame:CGRectMake(20, _imageView.frame.origin.y + _imageView.frame.size.height + 40, width, 20)];
    self.renzhengLable.text = @"认证:";
    [self.scrollView addSubview:self.renzhengLable];
    
    
    self.renzhengNameLable = [[UILabel alloc]initWithFrame:CGRectMake(20 + 40, _imageView.frame.origin.y + _imageView.frame.size.height + 40, width * 5, 20)];
    self.renzhengNameLable.text = @"无";
   
    
    [self.scrollView addSubview:self.renzhengNameLable];
    

    self.jianjieLable = [[UILabel alloc]initWithFrame:CGRectMake(20, self.renzhengLable.frame.origin.y + self.renzhengLable.frame.size.height + 10, width, 20)];
    self.jianjieLable.text = @"简介:";
    [self.scrollView addSubview:self.jianjieLable];
    

    self.jianjieNameLable = [[UILabel alloc]initWithFrame:CGRectMake(20 + 40, self.renzhengLable.frame.origin.y + self.renzhengLable.frame.size.height + 10, width *5, 20)];
    [self.scrollView addSubview:self.jianjieNameLable];
    
    
    
    
    
    
//    
//    self.dingweiLable = [[UILabel alloc]initWithFrame:CGRectMake(20, height/2+120, width, 30)];
//    self.dingweiLable.text = @"定位";
//    [self.scrollView addSubview:self.dingweiLable];
//    
//    
//    self.dingweiNameLable = [[UILabel alloc]initWithFrame:CGRectMake(20 + width, height/2+120, width, 30)];
//    [self.scrollView addSubview:self.dingweiNameLable];
//    

}


- (void)getInfor
{
    NSString *path = [NSString stringWithFormat:@"http://mobile.ximalaya.com/mobile/others/ca/homePage?device=iPhone&toUid=%@",[self.introduction.uid stringValue]];
    
    [NetHandler getDataWithURL:path completion:^(NSData *data) {
        
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        
                [self.imageView setImageWithURL:[NSURL URLWithString:[[dic objectForKey:@"mobileLargeLogo"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
        
        if ([[dic objectForKey:@"ptitle"] length] != 0) {
            self.renzhengNameLable.text = [dic objectForKey:@"ptitle"];
            self.renzhengNameLable.numberOfLines = 0;
            [self.renzhengNameLable sizeToFit];
        }

        if ([[dic objectForKey:@"personalSignature"] length] != 0) {
            self.jianjieNameLable.frame = CGRectMake(20 + 40, self.renzhengLable.frame.origin.y + self.renzhengLable.frame.size.height + 10, self.view.bounds.size.width / 6 * 5 - 30 , 20);
            self.jianjieNameLable.text = [dic objectForKey:@"personalSignature"];
            self.jianjieNameLable.numberOfLines = 0;
            [self.jianjieNameLable sizeToFit];
            
        }
        
        self.scrollView.contentSize = CGSizeMake(self.view.bounds.size.width, self.jianjieNameLable.frame.origin.y + self.jianjieNameLable.frame.size.height);
        
    }];
    
    
}

- (void)returnClicked:(UIButton *)button
{
    
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    
    
    
    
    
    // Dispose of any resources that can be recreated.
}









/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
